package com.bw.module_inspection.view

import android.view.View
import androidx.activity.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_base.view.BaseActivity
import com.bw.module_inspection.R
import com.bw.module_inspection.adapter.InspectionAgentAdapter
import com.bw.module_inspection.databinding.ActivityInspectionAgentBinding
import com.bw.module_inspection.viewmodel.InspectionViewModel

/**
 * 智慧园区-07-巡检管理V1.1-史建军-20250514
 */
@Route(path = RouterPath.PATH_INSPECTION_AGENT_ACTIVITY)
class InspectionAgentActivity : BaseActivity<ActivityInspectionAgentBinding>() {
   private lateinit var inspectionAgentAdapter: InspectionAgentAdapter
   @Autowired(name = "name")
   @JvmField
   var name:String=""
    @Autowired(name = "location")
    @JvmField
    var location:String=""

    private val vm by viewModels<InspectionViewModel> { ViewModelProvider.NewInstanceFactory()}


    override fun initView() {
        ARouter.getInstance().inject(this)
        name=intent.getStringExtra("name") ?:""
        location=intent.getStringExtra("location") ?:""
        if (name.isNotEmpty()&&location.isNotEmpty()){
            vm.getInspectionAgent(location,name)
        }
        vm.inspectionAgentSuccess.observe(this){
            inspectionAgentAdapter.data.addAll(it)
            inspectionAgentAdapter.notifyDataSetChanged()
        }
        mDataBinding.topLayout.ivBack.setOnClickListener {
            finish()
        }
        mDataBinding.topLayout.tvAdd.visibility=View.GONE
        mDataBinding.topLayout.ivMenus.visibility=View.VISIBLE
        mDataBinding.topLayout.tvGoBack.text="巡检代办"
        inspectionAgentAdapter=InspectionAgentAdapter()
        mDataBinding.rvAgent.adapter=inspectionAgentAdapter
        mDataBinding.rvAgent.layoutManager= LinearLayoutManager(this)
        inspectionAgentAdapter.setOnItemClickListener{_,_,position->
            ARouter.getInstance().build(RouterPath.PATH_INSPECTION_TASK_DETAIL_ACTIVITY).withString("patrolType",inspectionAgentAdapter.data[position].patrolType).withString("pointName",inspectionAgentAdapter.data[position].pointName).navigation()
        }








    }
    override fun getLayoutId(): Int =R.layout.activity_inspection_agent

}